// 工艺路线API调用服务
// 提供工艺路线的查询、创建、更新、删除等功能

import MesHelp from '../Http/MesHelp'

// 工艺路线API服务类
class RoutingService {
    
    /**
     * 查询工艺路线列表
     * @param {Object} queryParams - 查询参数
     * @returns {Promise<Object>} 工艺路线列表
     */
    static async getRoutingList(queryParams: any = {}): Promise<any> {
        try {
            const requestData = {
                RoutingName: queryParams.RoutingName || null,
                RoutStatus: queryParams.RoutStatus || null,
                PageIndex: queryParams.PageIndex || 1,
                PageSize: queryParams.PageSize || 10
            };
            
            const result = await MesHelp.get('/api/Process/GetRouting', {
                params: requestData
            });
            
            return result;
        } catch (error) {
            console.error('获取工艺路线列表失败:', error);
            throw error;
        }
    }
    
    /**
     * 获取工艺路线下拉选择数据
     * @returns {Promise<Object>} 工艺路线选择列表
     */
    static async getRoutingOptions(): Promise<any> {
        try {
            const result = await MesHelp.get('/api/Process/GetProccessRouting');
            return result;
        } catch (error) {
            console.error('获取工艺路线选项失败:', error);
            throw error;
        }
    }
    
    /**
     * 创建工艺路线
     * @param {Object} routingData - 工艺路线数据
     * @returns {Promise<Object>} 创建结果
     */
    static async createRouting(routingData: any): Promise<any> {
        try {
            const result = await MesHelp.post('/api/Process/RoutingCreate', routingData);
            return result;
        } catch (error) {
            console.error('创建工艺路线失败:', error);
            throw error;
        }
    }
    
    /**
     * 更新工艺路线
     * @param {Object} routingData - 工艺路线数据
     * @returns {Promise<Object>} 更新结果
     */
    static async updateRouting(routingData: any): Promise<any> {
        try {
            const result = await MesHelp.put('/api/Process/RoutingUpdate', routingData);
            return result;
        } catch (error) {
            console.error('更新工艺路线失败:', error);
            throw error;
        }
    }
    
    /**
     * 删除工艺路线
     * @param {Object} deleteParams - 删除参数
     * @returns {Promise<Object>} 删除结果
     */
    static async deleteRouting(deleteParams: any): Promise<any> {
        try {
            const result = await MesHelp.delete('/api/Process/RoutingDelete', {
                data: deleteParams
            });
            return result;
        } catch (error) {
            console.error('删除工艺路线失败:', error);
            throw error;
        }
    }
}

export default RoutingService;
